package ncorps.commun;

import java.awt.Color;
import static java.lang.Math.*;

public class ConditionInitiale {

    public static int _XDimG,  _YDimG;
    public static Color orange_rgb = Color.ORANGE;
    public static final int bleu0 = 255;
//    public static final int bleu1 = 150;
    public static final int bleu1 = 65536 * orange_rgb.getRed() + 256 * orange_rgb.getGreen() + 1 * orange_rgb.getBlue();
    public static final int rouge = 16711680;
    public static final int vert = 65280;
    private int _N;
    private double[][] gcoord;
    private String Type;
    private int _Diam;
    private int[] colorRef;

    public ConditionInitiale(int Diam, int _N) {
        this._Diam = Diam;
        ConditionInitiale._XDimG = Diam;
        ConditionInitiale._YDimG = Diam;
        this._N = _N;
        double[][] gcoordSYM = position();
        vitesse(gcoordSYM);
        colorRef = creerFlux(gcoordSYM);

    }

    public ConditionInitiale(ConditionInitiale CI, double[][] gcoord) {
        this._Diam = CI._Diam;
        ConditionInitiale._XDimG = CI._Diam;
        ConditionInitiale._YDimG = CI._Diam;
        this._N = CI._N;
        colorRef = CI.colorRef;
        this.gcoord = gcoord;

    }

    private int[] creerFlux(double[][] gcoordSYM) {

        colorRef = new int[_N];
        double zone = _Diam / 6;
        for (int n = 0; n < _N; n++) {
            if (gcoordSYM[n][2] < zone) {
                colorRef[n] = rouge;
            } else if ((gcoordSYM[n][2] >= zone) && (gcoordSYM[n][2] < 2 * zone)) {
                colorRef[n] = vert;
            } else if (gcoordSYM[n][2] >= 2 * zone) {
                colorRef[n] = bleu1;
            }
        }
        return colorRef;
    }

    private double[][] position() {
        gcoord = new double[_N][5];
        double[][] gcoordSYM = new double[_N][5];
        for (int n = 0; n < _N; n++) { //masses = 1
            gcoord[n][0] = 1;
        }
        //
//        gcoord[0][0] = 1000;//masse centrale
        //
        for (int n = 0; n < _N; n++) {
            gcoordSYM[n][1] = 2 * PI * random();
            gcoordSYM[n][2] = (_Diam / 2) * random();
            gcoord[n][1] = gcoordSYM[n][2] * cos(gcoordSYM[n][1]) + _Diam / 2;
            gcoord[n][2] = gcoordSYM[n][2] * sin(gcoordSYM[n][1]) + _Diam / 2;
        }
        //
//        gcoord[0][1] = _Diam / 2;//masse centrale
//        gcoord[0][2] = _Diam / 2;//masse centrale
        //
        return gcoordSYM;
    }

    private double[][] vitesse(double[][] gcoordSYM) {
        for (int n = 0; n < _N; n++) {
            gcoord[n][3] = 10 * cos(gcoordSYM[n][1] + PI / 2);
            gcoord[n][4] = 10 * sin(gcoordSYM[n][1] + PI / 2);
        }
        return gcoord;
    }

    public void set_N(int _N) {
        this._N = _N;
    }

    public static void set_XDimG(int _XDimG) {
        ConditionInitiale._XDimG = _XDimG;
    }

    public static void set_YDimG(int _YDimG) {
        ConditionInitiale._YDimG = _YDimG;
    }

    public void setGcoord(double[][] gcoord) {
        this.gcoord = gcoord;
    }

    public double[][] getGcoord() {
        return gcoord;
    }

    public int get_N() {
        return _N;
    }

    public int get_XDimG() {
        return _XDimG;
    }

    public int get_YDimG() {
        return _YDimG;
    }

    public int[] getColorRef() {
        return colorRef;
    }

    public int get_Diam() {
        return _Diam;
    }
}
